package com.yuefan;

import org.junit.Test;

import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class TestFruit {
    @Test
    public void test1() {
        List<Fruit> list = new ArrayList<>();
        //假设水果都是10斤
        list.add(new Fruit("苹果", 10, 8, 1));
        list.add(new Fruit("草莓", 10, 13, 1));
        assertEquals(210.0,getAmountPrice(list, false),0.001);
        System.out.println("商品价格总额为：" + getAmountPrice(list, false));

    }

    @Test
    public void test2() {
        List<Fruit> list = new ArrayList<>();
        list.add(new Fruit("苹果", 10, 8, 1));
        list.add(new Fruit("草莓", 10, 13, 1));
        list.add(new Fruit("芒果", 10, 20, 1));
        assertEquals(410.0,getAmountPrice(list, false),0.001);
        System.out.println("商品价格总额为：" + getAmountPrice(list, false));
    }

    @Test
    public void test3() {
        List<Fruit> list = new ArrayList<>();
        list.add(new Fruit("苹果", 10, 8, 1));
        list.add(new Fruit("草莓", 10, 13, 0.8)); //草莓八折
        list.add(new Fruit("芒果", 10, 20, 1));
        assertEquals(384.0,getAmountPrice(list, false),0.001);
        System.out.println("商品价格总额为：" + getAmountPrice(list, false));
    }

    @Test
    public void test4() {
        List<Fruit> list = new ArrayList<>();
        list.add(new Fruit("苹果", 10, 8, 1));
        list.add(new Fruit("草莓", 10, 13, 0.8)); //草莓八折
        list.add(new Fruit("芒果", 10, 20, 1));
        assertEquals(374.0,getAmountPrice(list, true),0.001);
        System.out.println("商品价格总额为：" + getAmountPrice(list, true)); //开启满减
    }

    public double getAmountPrice(List<Fruit> fruits, Boolean isFullDiscoun) {
        double amountPrice = 0;
        for (Fruit fruit : fruits) {
            amountPrice += fruit.getAmountPrice();
        }
        if (isFullDiscoun){
            FullDiscount FullDiscount = new FullDiscount(100, 10);
            amountPrice = FullDiscount.apply(amountPrice);
        }
       return amountPrice;
    }
}
